class Date:
    def __init__(self, year, month, day):
        self.year = year
        self.month = month
        self.day = day

    @classmethod
    def from_string(cls, date_str):
        # 解析字符串并返回类实例（支持多态）
        year, month, day = map(int, date_str.split("-"))
        return cls(year, month, day)  # cls可能是子类

# 使用类方法创建实例
date = Date.from_string("2023-10-05")
print(date.year, date.month, date.day)  # 输出: 2023 10 5


class MathUtils:
    @staticmethod
    def add(a, b):
        # 不依赖类或实例的纯功能
        return a + b

# 直接调用静态方法
result = MathUtils.add(3, 5)
print(result)  # 输出: 8


class SubDate(Date):
    @classmethod
    def from_string(cls, date_str):
        # 子类自定义解析逻辑
        return cls(2000, 1, 1)  # 返回子类实例

sub_date = SubDate.from_string("1999-12-31")
print(isinstance(sub_date, SubDate))  # 输出: True


class StringUtils:
    @staticmethod
    def is_palindrome(s):
        print(s)
        print(s[::-1])
        return s == s[::-1]

print(StringUtils.is_palindrome("radar"))  # 输出: True
